#include <iostream>
#include <vector>

class Solution {
public:
    std::vector<int> canSeePersonsCount(std::vector<int>& heights) {
        int n = heights.size();
        std::vector<int> result(n, 0);
        std::vector<int> stack;
        
        for (int i = 0; i < n; ++i) {
            while (!stack.empty() && heights[i] > heights[stack.back()]) {
                result[stack.back()]++;
                stack.pop_back();
            }
            if (!stack.empty()) {
                result[stack.back()]++;
            }
            stack.push_back(i);
        }
        
        return result;
    }
};

int main() {
    std::vector<int> heights;
    heights.push_back(10);
    heights.push_back(6);
    heights.push_back(8);
    heights.push_back(5);
    heights.push_back(11);
    heights.push_back(9);
    
    Solution sol;
    std::vector<int> result = sol.canSeePersonsCount(heights);
    
    std::cout << "[";
    for (int i = 0; i < result.size(); ++i) {
        if (i > 0) {
            std::cout << ", ";
        }
        std::cout << result[i];
    }
    std::cout << "]" << std::endl;
    
    return 0;
}
